#include <iostream>
#include <memory>
template <typename T>
class vector{
public:
explicit vector(int size): my_size(size), data(new T[my_size]){}
vector(void): my_size(0) {}
private:
int my_size;
std::unique_ptr<T[]> data;
};
class vector_bool_proxy{
public:
vector_bool_proxy(unsigned char& byte, int p)
: byte(byte), mask(1<<p) {}
operator bool() const{ return byte&mask; }
vector_bool_proxy& operator=(bool b){
if(b) byte |= mask;
else byte &= ~mask;
return *this;
}
private:
unsigned char& byte;
unsigned char mask;
};
template<> class vector<bool>{
public:
vector(int size): my_size(size), data(new unsigned char[my_size]) {}
vector(void): my_size(0) {}
vector_bool_proxy operator[](int i){
return {data[i/8], i%8};
}
private:
int my_size;
std::unique_ptr<unsigned char[]> data;
};
int main(void){
vector<bool> bool_vec1(4);
bool_vec1[0]=true;
bool_vec1[1]=false;
bool_vec1[2]=false;
bool_vec1[3]=true;
std::cout<<"bool_vec1:"<<std::endl;
for(int i=0; i<4; i++){
std::cout<<i<<": "<<bool_vec1[i]<<std::endl;
}
return 0;
}